<template>
  <div class="printForm">
    <div class="area-header">
      <span class="area-header-title">{{ $t('申请单') }}</span>
    </div>
    <table class="printTable">
      <tr>
        <td class="tit">{{ $t('申请标题') }}</td>
        <td colspan="3">{{ form.actTitle }}</td>
      </tr>
      <tr>
        <td class="tit">{{ $t('申请人') }}</td>
        <td>
          <UserSelect
            v-model="form.userId"
          />
        </td>
        <td class="tit">{{ $t('申请时间') }}</td>
        <td>
          {{ parseTime(form.applyTime) }}
        </td>
      </tr>
      <tr>
        <td class="tit">{{ $t('申请部门') }}</td>
        <td>
          {{ form.deptName }}
        </td>
        <td class="tit">{{ $t('申请人岗位') }}</td>
        <td>
          {{ form.postNames }}
        </td>
      </tr>

      <tr>
        <td class="tit">{{ $t('出差方式') }}</td>
        <td>
          {{ form.methodLabel }}
        </td>
        <td class="tit">{{ $t('预计金额(元)') }}</td>
        <td>
          {{ moneyFormat(form.money) }}
        </td>

      </tr>
      <tr>
        <td class="tit">{{ $t('出差类型') }}</td>
        <td>
          {{ typeFormat(form.type) }}
        </td>
        <td class="tit">{{ $t('目的地类型') }}</td>
        <td>
          <dictSelect
            v-model="form.destination"
            :clearable="true"
            dictionary="destination_type"
          />
        </td>
      </tr>
      <tr>
        <td class="tit">{{ $t('是否确定往返时间') }}</td>
        <td>
          <dictSelect
            v-model="form.isDetermine"
            :clearable="true"
            dictionary="sys_yes_no"
          />
        </td>
        <td class="tit">{{ $t('时间') }}</td>
        <td>
          {{ parseTime(form.goOff) }} / {{ parseTime(form.endTimes) }}
        </td>

      </tr>
      <tr>
        <td class="tit">{{ $t('同行人员') }}</td>
        <td colspan="3">
          {{ form.partnersId }}
        </td>
      </tr>
      <tr>
        <td class="tit">{{ $t('备注') }}</td>
        <td colspan="3">
          {{ form.remark }}
        </td>
      </tr>
    </table>

    <div v-if="form.reasonsList && form.reasonsList.length > 0">
      <div class="area-header">
        <span class="area-header-title">{{ $t('出差事由') }}</span>
      </div>
      <table class="previewTable">
        <thead>
          <th>{{ $t('起始时间') }}</th>
          <th>{{ $t('事由') }}</th>
        </thead>
        <tbody>
          <tr v-for="(v, ind) in form.reasonsList" :key="ind">
            <td>
              {{ parseTime(v.startTime) }} / {{ parseTime(v.endTimes) }}
            </td>
            <td>{{ v.reason }}</td>
          </tr>
        </tbody>
      </table>
    </div>

    <!--文件-->
    <FileView :list.sync="form.fileList" data-type="oa_travel" />

  </div>
</template>

<script>
import { getOaBusinessTravel } from '@/api/oa/travel/oaTravel'
export default {
  name: 'OaTravelForm',
  components: {},
  data() {
    return {
      loading: false,
      // 表单参数
      form: {
        // 出差事由
        reasonsList: [],
        fileList: []
      },
      // 出差类型
      typeOptions: [],
      // 出差方式
      methodsOptions: []
    }
  },
  mounted() {
    this.$bus.$emit('async_done')
  },
  created() {
    // 出差类型
    this.getDicts('oa_business_travel_type').then((response) => {
      this.typeOptions = response.data
    })
    // 出差方式
    this.getDicts('oa_business_travel_methods').then((response) => {
      this.methodsOptions = response.data
    })
  },
  methods: {
    typeFormat(row) {
				return this.$t(this.selectDictLabel(this.typeOptions, row))
    },
    methodFormat(row) {
				return this.$t(this.selectDictLabel(this.methodsOptions, row))
		},
    // 初始化数据
    init(data) {
      if (data != null && data !== '' && data.id !== undefined) {
        this.loading = true
        getOaBusinessTravel(data.id).then((response) => {
          this.form = response.data
          this.loading = false
        })
      } else {
        this.loading = false
      }
    }
  }
}
</script>
